// dllmain.cpp : Defines the entry point for the DLL application.
#include "stdafx.h"


#define IVALIBAPI __declspec(dllexport)
#include "Iva_dll.h"



HINSTANCE g_IvaDll;
HHOOK g_IvaHook;
LRESULT WINAPI GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam);



BOOL APIENTRY DllMain( HMODULE hModule,
                       DWORD  ul_reason_for_call,
                       LPVOID lpReserved
					 )
{
	switch (ul_reason_for_call)
	{
	case DLL_PROCESS_ATTACH:
            g_IvaDll = hModule;
            break;

	case DLL_THREAD_ATTACH:
	case DLL_THREAD_DETACH:
	case DLL_PROCESS_DETACH:
            break;
	}
	return TRUE;
}


BOOL WINAPI SetIvaHook(DWORD dwExploreThreadId){
	BOOL fOK = FALSE;

	if(dwExploreThreadId != 0){
		g_IvaHook = ::SetWindowsHookEx(WH_MOUSE, GetMsgProc, g_IvaDll, dwExploreThreadId);
		fOK = (g_IvaHook != NULL);

		//if(fOK){
		//	//The hook was installed successfully; force a benign
		//	fOK = ::PostThreadMessage(dwExploreThreadId, WM_NULL, 0, 0);
		//}
	}
	else{
		fOK = ::UnhookWindowsHookEx(g_IvaHook);
		g_IvaHook = NULL;
	}
	return fOK;
}

LRESULT WINAPI GetMsgProc(int nCode, WPARAM wParam, LPARAM lParam){
	if(wParam == WM_LBUTTONDBLCLK){
		::OutputDebugString(TEXT("Received DBLCLK msg in Explore process\n"));
		 HWND = desktop = ::FindWindow(L"SysListView32", NULL);
		 ::ShowWindow(HWND, SW_HIDE);
		 int item = -1;
		 //while(item = ::ListView_GetNextItem(desktop, item, LVNI_ALL)){
		 //}
	}
	return ::CallNextHookEx(g_IvaHook, nCode, wParam, lParam);
}